<?
ini_set("display_errors",1);
include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

init_session();

if (empty($_SESSION['user_id'])) {
	include($_SERVER['DOCUMENT_ROOT'].'/portals/login.inc.php');
	exit;
}

include($_SERVER['DOCUMENT_ROOT'].'/portals/header.inc.php');

$id = intval(@$_GET['id']);


if ($id) {
	$sql = array();
	
	$sql['columns'] = 'portal.*,user.realname';
	$sql['tables'] = array('portal');
	$sql['tables'][] = "left join `user`  USING (user_id)";

	$sql['wheres'] = array('status_id = 1');
	$sql['wheres'][] = "portal_id = $id";
	$sql['wheres'][] = "user_id = ".intval($_SESSION['user_id']);
	
	$query = sqlMakeQuery($sql);
	
	$c = getrow($query);
	
	
	
} 

if (empty($c)) 
	die("404 Not Found - We dont have this portal?");
	
?>


<table class="viewtable">

<tr><td colspan="1" class="viewheader">

<span style="font-weight:normal">Portal</span>: <a href="http://<? ehec('domain'); ?>.portal.geographs.org/" target="_blank"><? ehec('title'); ?></a>

</td>
<td class="viewheader" style="font-size:0.7em">
<?
        $count = getOne("SELECT COUNT(*) FROM p2.gridimage{$id}_bi_view");
        if ($count)
                print " $count <a href=\"http://".hec('domain').".portal.geographs.org/statistics.php\">image(s)</a>";
?>
</td>

</tr>

<tr><td>

<p>View portal: <a href="http://<? ehec('domain'); ?>.portal.geographs.org/" target="_blank" class="feature">http://<b><? ehec('domain'); ?></b>.portal.geographs.org/</a></p>

<? 

if (!empty($c['excerpt'])) {
	print "<p><small><i>excerpt:</i></small><br/>".hec('excerpt')."</p>";
}

if (!empty($c['description'])) {
	print "<p><small><i>description:</i></small><br/>".hec('description')."</p>";
} 

?>

</td>
<td class="viewactions">

&middot; <a href="edit.php?id=<? echo $id; ?>"><b>Edit Portal Details</b></a><br/><br/>
&middot; <a href="edit.php?id=<? echo $id; ?>&amp;adv=1">Advanced Options</a>

</td></tr>

<tr><td colspan="2" class="viewheader">

<i>Images from</i> Geograph British Isles

</td></tr>

<tr><td>

<? 

$table = "p2.gridimage{$id}_bi";
$count = getAll("SELECT status_id,COUNT(*) AS count,SUM(gi.gridimage_id IS NOT NULL) AS active FROM $table LEFT JOIN geograph_live.gridimage_search gi USING (gridimage_id) GROUP BY status_id");
if ($count) {
	$status = getAssoc("SELECT status_id,name FROM status");
	print "<small><i>image breakdown:</i></small><table border=1 cellspacing=0 cellpadding=4 class=inner><tr><th>Image Status</th><th>Count</th><th>Active</th></tr>";
	foreach ($count as $idx => $row) {
		$status_id = $row['status_id'];
		print "<tr><th>{$status[$status_id]}</th><td align=right>{$row['count']}</td><td align=right>{$row['active']}</td></tr>";
		//todo - if 'pending' link to moderation
	}
	print "</table>";


} else {
	print "<i>No images yet! <b><a href=\"filters.php?id=$id\">Define Filters</a></b></i>";
}


?>

        <div style="font-size:0.7em; color:red;padding:2px; font-weight:bold">
               Note: during the alpha stage we only display a very small selection of the available, <br/>typically maximum 500 images, and only includes images below id 2009306</div>

</td>
<td class="viewactions">

	&middot; <a href="filters_view.php?id=<? echo $id; ?>">View Filters</a> <br/>
	&middot; <b><a href="filters.php?id=<? echo $id; ?>">Edit Filters</a></b> <br/><br/>

	<small>&middot; <a href="reset.php?id=<? echo $id; ?>" style="color:red">Reset Portal</a><br/> (confirmation required)</small>

</td></tr>


<tr><td colspan="2" class="viewheader">
<i>Images from</i> Geograph Germany
</td></tr>

<tr><td colspan="2">
<p>Coming soon... (not implemented yet)</p>
</td></tr>




<tr><td colspan="2" class="viewheader">
<i>Images from</i> Geograph Channel Islands
</td></tr>

<tr><td colspan="2">
<p>Coming soon... (not implemented yet)</p>
</td></tr>


</table>

<div class="rightgray">This entry added <? echo date('r',strtotime($c['created'])); ?></div>

<? 


include($_SERVER['DOCUMENT_ROOT'].'/portals/footer.inc.php');
